#ifndef __IM_DATA_LIST_H__
#define __IM_DATA_LIST_H__

#include <im_base_types.h>
#include <im_quark.h>

/**
 * @defgroup IMDataList
 * @ingroup PrivateIMBus
 * @{
 */

/** @struct IMDataList
 * @brief Object to store a list of keyed data.
 */

IM_BEGIN_DECLS

typedef struct _IMDataList  IMDataList;

typedef IMBool      (*IMDataForeachFunc)    (IMQuark              key_id,
                                             IMPointer            data,
                                             IMPointer            user_data);

/* Keyed Data List
 */
void        im_datalist_init                (IMDataList         **datalist);
void        im_datalist_clear               (IMDataList         **datalist);
IMSize      im_datalist_length              (IMDataList         **datalist);
IMPointer   im_datalist_id_get_data         (IMDataList         **datalist,
                                             IMQuark              key_id);
void        im_datalist_id_set_data_full    (IMDataList         **datalist,
                                             IMQuark              key_id,
                                             IMPointer            data,
                                             IMDestroyFunc        destroy_func);
IMPointer   im_datalist_id_steal            (IMDataList         **datalist,
                                             IMQuark              key_id);
/**
 * @brief Call func() against each data in the datalist.
 *
 * If func() returns FALSE, then it'll return FALSE immediately, without
 * iterating remained data.
 *
 * @return TRUE if every call of func() return TRUE, otherwise returns FALSE.
 */
IMBool      im_datalist_foreach             (IMDataList         **datalist,
                                             IMDataForeachFunc    func,
                                             IMPointer            user_data);
#define     im_datalist_id_set_data(dl, q, d)       \
    im_datalist_id_set_data_full ((dl), (q), (d), 0)
#define     im_datalist_id_remove_data(dl, q)       \
    im_datalist_id_set_data ((dl), (q), 0)
#define     im_datalist_get_data(dl, k)             \
    (im_datalist_id_get_data ((dl), im_quark_try_string (k)))
#define     im_datalist_set_data_full(dl, k, d, f)  \
    im_datalist_id_set_data_full ((dl), im_quark_from_string (k), (d), (f))
#define     im_datalist_steal(dl, k)                \
    im_datalist_id_steal ((dl), im_quark_try_string (k))
#define     im_datalist_set_data(dl, k, d)          \
    im_datalist_set_data_full ((dl), (k), (d), 0)
#define     im_datalist_remove_data(dl, k)          \
    im_datalist_id_set_data ((dl), im_quark_try_string (k), 0)


IM_END_DECLS

#endif
/**  @} */

/*
vi:ts=4:nowrap:ai:expandtab
*/
